using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ApiDoc.Admin.Server
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string path = AppDomain.CurrentDomain.BaseDirectory + "run.log";
            try
            {
                CreateHostBuilder(args)
                .ConfigureHostConfiguration(configBuilder => {

                    configBuilder.SetBasePath(AppDomain.CurrentDomain.BaseDirectory);
                    configBuilder.AddJsonFile("Json\\host.json", true);

                })
                 .ConfigureLogging((context, loggingBuilder) =>
                 {
                     loggingBuilder.ClearProviders();
                     loggingBuilder.AddLog4Net(new Log4NetProviderOptions()
                     {
                         Log4NetConfigFileName = "Configs\\log4net.config",
                         Watch = true
                     });
                 })
                 .UseWindowsService()
              .Build()
              .Run();
            }
            catch (Exception ex)
            {
                System.IO.File.AppendAllText(path, ex.Message);
            }
 
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args) 
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
}
